<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>绑定帐号n</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

<link rel="stylesheet" href="${url}/css/bootstrap.min.css" />
<link rel="stylesheet" href="${url}/css/font-awesome.min.css" />

<link rel="stylesheet" href="${url}/css/fc-fonts.css" />
<link rel="stylesheet" href="${url}/css/fc.min.css" />

<!--[if lte IE 9]>
<link rel="stylesheet" href="${url}/css/fc-part2.min.css" />
<![endif]-->
<link rel="stylesheet" href="${url}/css/fc-rtl.min.css" />

<!--[if lte IE 9]>
  <link rel="stylesheet" href="${url}/css/fc-ie.min.css" />
<![endif]-->
<link rel="stylesheet" href="${url}/css/fc-custom.css" />

<!--[if lt IE 9]>
<script src="${url}/js/html5shiv.js"></script>
<script src="${url}/js/respond.min.js"></script>
<![endif]-->
</head>

<body class="login-layout">
<div class="main-container">
	<div class="main-content">
		<div class="row">
			<div class="col-sm-10 col-sm-offset-1">
				<div class="login-container">
					<div class="center">
						<h1>
							<i class="ace-icon fa fa-leaf green"></i>
							<span class="red">FinalCMS</span>
							<span class="white" id="id-text2">Application</span>
						</h1>
						<h4 class="blue" id="id-company-text">&copy; My Company</h4>
					</div>
					<div class="space-6"></div>

					<div class="position-relative">
						<div id="login-box" class="login-box visible widget-box no-border">
							<div class="widget-body">
								<div class="widget-main">
									<h4 id="_msg" class="header blue lighter bigger">
										<i class="ace-icon fa fa-coffee green"></i>
										<?if(isEmpty(error)){?>
										<b>绑定邮箱和密码用于以后登录</b>
										<?}else{?>
										<b class="red"> ${error!""} </b>
										<?}?>
									</h4>
									<div class="space-6"></div>
									<form id="loginForm" action="${url}/user/bind" method="post">
										<input type="hidden" name="redirect" value="${redirect!}" />
										<input type="hidden" name="sso_id" value="${sso_id!}" />
										<input type="hidden" name="sso_type" value="${sso_type!}" />
										<fieldset>
											<label class="block clearfix">
												<span class="block input-icon input-icon-right">
													<input type="text" class="form-control" placeholder="用户名" name="username" id="username" value="${name}"/>
													<i class="ace-icon fa fa-user"></i>
												</span>
											</label>
											<label class="block clearfix">
												<span class="block input-icon input-icon-right">
													<input type="text" class="form-control" placeholder="邮箱" name="email" id="email" />
													<i class="ace-icon fa fa-envelope"></i>
												</span>
											</label>
											<label class="block clearfix">
												<span class="block input-icon input-icon-right">
													<input type="text" class="form-control" placeholder="密码"  name="password" id="password"/>
													<i class="ace-icon fa fa-lock"></i>
												</span>
											</label>
											
											<div class="space"></div>

											<div class="clearfix">
												<button type="button" id="loginBtn" class="width-35 pull-right btn btn-sm btn-primary">
													<i class="ace-icon fa fa-key"></i>
													<span class="bigger-110" id="subBtn">绑定</span>
												</button>
											</div>
											<div class="space-4"></div>
										</fieldset>
									</form>
								</div><!-- /.widget-main -->
							</div><!-- /.widget-main -->
						</div><!-- /.widget-body -->
					</div><!-- /.login-box -->
				</div><!-- /.position-relative -->
			</div>
		</div><!-- /.row -->
	</div><!-- /.main-content -->
</div><!-- /.main-container -->

<script type="text/javascript" src='${url}/js/jquery1.11.0.min.js'></script>
<script type="text/javascript" src='http://cdn.bootcss.com/jquery-validate/1.14.0/jquery.validate.min.js'></script>
<script type="text/javascript" src='http://cdn.bootcss.com/jquery.form/3.51/jquery.form.min.js'></script>
<script type="text/javascript">
jQuery(function($) {
	$(document).keypress(function(e) {
	    // 回车键事件  
       if(e.which == 13) {  
    	   $("#loginBtn").click();
	   }
	}); 
	$('#loginForm').validate({
		submitHandler:function(form){
		      $(form).ajaxSubmit({
		        type:'POST',
		        dataType:"json",
		        url:"${url}/ajax/bind?time="+ (new Date()).getTime(),
		        success: function(data){
		        	if(data.result){
		        		location.href="${redirect!'/'}";
		        	}else{
		        		$('#_msg > b').addClass('red').text(data.message)
		        	}
		        }
		      });
		},
		rules:{
			username:{
				required: true,
				rangelength: [6,32],
				remote:{
					type:"post",
					url: "${url}/user/userExist?time="+ (new Date()).getTime(),
					data:{key:function(){return $.trim($("#email").val());}},
					dataType:"json",
					dataFilter: function(data) {
						if (data)
                    		return true;
                    	else
                        	return false;
                	}
				}
			},
			password:{
				required: true,
				rangelength: [6,16]
			},
			email:{
				required: true,
				email:true,
				remote:{
					type:"post",
					url: "${url}/ajax/emailExist?time="+ (new Date()).getTime(),
					data:{key:function(){return $.trim($("#email").val());}},
					dataType:"json",
					dataFilter: function(data) {
						if (data)
                    		return true;
                    	else
                        	return false;
                	}
				}
			}
		},
		messages:{
			username:{
				required: "请输入用户名！",
				rangelength:"用户名长度必须在6-32个字符之间！",
				remote: "用户名存在，不可用！"
			},
			email:{
				required: "请输入邮箱！",
				email:"请输入合法的email地址！",
				remote: "邮箱存在，不可用！"
			},
			password: {
				required: "请输入密码！",  
				rangelength: "密码必须在6-16个字符之间！"
			}
		},
		showErrors : function(errorMap, errorList) {  
			var msg = '';  
			$.each(errorList, function(i, v) {  
				msg += (v.message + '\r\n'); 
				return false; 
			});  
			$('#_msg > b').addClass('red').text(msg);
		},  
		/* 失去焦点时不验证 */  
		onfocusout : false  
	});
	//登录
	$("#loginBtn").click(function(){
		$("#loginForm").submit();
	});
});
</script>
</body>
</html>